package com.example.votemanage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.votemanage.entity.VoteSubject;
import com.example.votemanage.service.IVoteSubjectService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xingcheng
 * @since 2024-06-06
 */
@Controller
public class VoteSubjectController {
    @Autowired
    IVoteSubjectService voteSubjectService;
    @RequestMapping("/index")
    public String selectAllVoteSubject(@RequestParam(name="pageindex", required=false, defaultValue="1") int pageindex,
                                       @RequestParam(name="pageSize", required=false, defaultValue="5") int pageSize,
                                       @RequestParam(name="vsTitle", required=false, defaultValue="") String vsTitle,
                                       HttpServletRequest request) {
        Page<VoteSubject> subjectPage = new Page<>(pageindex, pageSize);
        request.setAttribute("subjectPage", voteSubjectService.selectAllVoteSubject(subjectPage, vsTitle));
        request.setAttribute("pageSize", pageSize);
        request.setAttribute("vsTitle", vsTitle);
        return "index";
    }
    @RequestMapping("/selectAllSubject")
    public String selectAllSubject(int vsid,HttpServletRequest request){
        VoteSubject voteSubject=voteSubjectService.selectAllSubject(vsid);
        request.setAttribute("voteSubject",voteSubject);
        return "view";
    }
    @RequestMapping("/manage")
    public String manage(@RequestParam(name="pageindex",required = false,defaultValue = "1") int pageindex,
                         @RequestParam(name="pageSize",required = false,defaultValue = "5") int pageSize,
                         HttpServletRequest request,@RequestParam(name="vsTitle", required=false, defaultValue="")String vsTitle){
        Page<VoteSubject> subjectPage = new Page<>(pageindex, pageSize);
        request.setAttribute("subjectPage", voteSubjectService.selectAllVoteSubject(subjectPage,vsTitle));
        request.setAttribute("pageSize",pageSize);
        request.setAttribute("vsTitle", vsTitle);
        return "manage";
    }
    @RequestMapping("/addsuccess")
    public String addsuccess(){
        return "add_success";
    }
}
